<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/10/29
 * Time: 15:16
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Commentzc extends Base
{
    /**
     * 上传文件列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $params = input('param.');
            $where = [];
            if(isset($params['up_name']) && $params['up_name'] != ''){
                $where['comment_user_name|zc_title'] = ['like', '%' . $params['up_name'] . '%'];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_zhengce_comment')->alias('a')
                ->join('up_zhengce i','a.comment_zc_id=i.zc_id','LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_zhengce_comment')->alias('a')
                ->join('up_zhengce i','a.comment_zc_id=i.zc_id','LEFT')
                ->where($where)
                ->field('a.*, zc_title')
                ->page($Nowpage,$limits)
                ->order('comment_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    /**
     * 删除文件
     * @return \think\response\Json
     */
    public function fileDel(){
        $up_id = input('id');
        $res = Db::table('up_zhengce_comment')->where('comment_id', $up_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    
}